local CONST_ASSASSIN_STAR_COST = 45
local CONST_ASSASSIN_STAR_LEVEL = 80
local CONST_ASSASSIN_STAR_ITEMID = 7368

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)


function onCreatureAppear(cid)                npcHandler:onCreatureAppear(cid)        end
function onCreatureDisappear(cid)            npcHandler:onCreatureDisappear(cid)        end
function onCreatureSay(cid, type, msg)        npcHandler:onCreatureSay(cid, type, msg)    end
function onThink()                        npcHandler:onThink()                        end

local count = 1

function assassinStarCallback(cid, message, keywords, parameters)
    if(cid ~= npcHandler.focus) then
        return false
    end
    if(not(getPlayerStorageValue(cid,120001) == 1 and getPlayerStorageValue(cid,120002) == 1)) then
        npcHandler:say('I only sell assassin stars to more experienced people.')
        keywordHandler:reset()
    elseif(getPlayerLevel(cid) < CONST_ASSASSIN_STAR_LEVEL) then
        npcHandler:say('Your level is too low.')
        keywordHandler:reset()
    else
        count = ShopModule:getCount(message)
        npcHandler:say('I see that you are experienced enough. Do you want to buy ' .. count .. ' for ' .. count*CONST_ASSASSIN_STAR_COST .. ' gold coins?')
    end
    return true
end

function buyAssassinStarCallback(cid, message, keywords, parameters)
    if(cid ~= npcHandler.focus) then
        return false
    end
    
    if(doPlayerBuyItem(cid, CONST_ASSASSIN_STAR_ITEMID, count, count*CONST_ASSASSIN_STAR_COST) == LUA_NO_ERROR) then
        npcHandler:say('Here you are.')
    else
        npcHandler:say('You cannot afford that.')
    end
    keywordHandler:reset()
    return true
end

local node = keywordHandler:addKeyword({'assassin'}, assassinStarCallback)
node:addChildKeyword({'yes'}, buyAssassinStarCallback)
node:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, text = 'Then what do you want?', reset = true})

local keywordModule = KeywordModule:new()
npcHandler:addModule(keywordModule)

keywordModule:addKeyword({'aol'}, 'I sell AOL for 2k.')

npcHandler:addModule(FocusModule:new())